import BaseWidget from "./BaseWidget";

const {ccclass, menu} = cc._decorator;

@ccclass
@menu("Widget/OrientationWidget")
export default abstract class OrientationWidget extends BaseWidget {
    protected onLoad(): void{
        cc.view.on("canvas-resize", this._onCanvasSizeChanged, this);
        window.addEventListener("orientationchange", this._onOrientationchange.bind(this));
        this._onCanvasSizeChanged();
    }

    private _onOrientationchange(){
        this.scheduleOnce(this.onCanvasSizeChanged.bind(this), 0);
        // this.onCanvasSizeChanged();
    }

    private _onCanvasSizeChanged(){
        this.onCanvasSizeChanged();
    }

    protected abstract onCanvasSizeChanged(): void;

}